package com.winit.openapi.rma.builder;
import java.math.RoundingMode;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.winit.oms.spi.rma.command.RMAOrderCommand;
import com.winit.oms.spi.rma.vo.RMAClaimTagVo;
import com.winit.oms.spi.rma.vo.RMAEnumConstant;
import com.winit.oms.spi.rma.vo.RMAFilePathVo;
import com.winit.oms.spi.rma.vo.RMAItemVo;
import com.winit.oms.spi.rma.vo.RMAOrderMerchandiseVo;
import com.winit.oms.spi.rma.vo.RMAOrderVo;
import com.winit.openapi.constants.ErrorCode;
import com.winit.openapi.exception.ApiException;
import com.winit.openapi.util.DateUtil;

/**
 * 退货单构建器类
 * 
 * @version <pre>
 * Author	  Version		Date		Changes
 * dinghua.an	1.0  		2016年3月9日 	Created
 *
 * </pre>
 * @since 1.
 */
public class RmaOrderBuilder {

    /**
     * 构建参数公用方法
     * 
     * @param json
     * @return
     */
    public static RMAOrderVo buildRMAOrder(JSONObject json) {
        RMAOrderVo vo = new RMAOrderVo();
        if (json.containsKey("returnExpressNo")) {
            vo.setExpressNo(json.getString("returnExpressNo").trim());
            vo.setCustomerExpressNo(json.getString("returnExpressNo").trim());
        }
        if (json.containsKey("warehouseCode")) {
            vo.setWarehouseCode(json.getString("warehouseCode").trim());
        }
        if (json.containsKey("returnGoodsAddr")) {
            vo.setRmaAddress(json.getString("returnGoodsAddr").trim());
        }
        if (json.containsKey("returnGoodsOrderNo")) {
            vo.setRmaNo(json.getString("returnGoodsOrderNo").trim());
        }
        if (json.containsKey("winitProductCode")) {
            vo.setWinitProductCode(json.getString("winitProductCode").trim());
        }
        if (json.containsKey("isPhotograph")) {
            vo.setIsPhotograph(json.getString("isPhotograph").trim());
        }
        if (json.containsKey("source")) {
            vo.setSource(json.getString("source").trim());
        }
        if (json.containsKey("sellerOrderNo")) {
            if(StringUtils.isNotBlank(json.getString("sellerOrderNo").trim())){
                vo.setCustomerOrderNo(json.getString("sellerOrderNo").trim());
            }
        }
        String source = json.getString("source");
        if (RMAEnumConstant.OrderSource.ER.getType().equals(source)) {
            buildRMAOrderByEbay(json, vo);
        } else if (RMAEnumConstant.OrderSource.NR.getType().equals(source)) {
            buildBaseEbayInfo(json, vo);
            if (json.containsKey("claimTagNo")) {
                vo.setClaimTagNo(json.getString("claimTagNo").trim());
            }
        } else if (RMAEnumConstant.OrderSource.OR.getType().equals(source)) {
            if (json.containsKey("outboundOrderNo")) {
                vo.setOutboundOrderNo(json.getString("outboundOrderNo").trim());
            }
            buildBaseEbayInfo(json, vo);
        } else {
            throw new ApiException(ErrorCode.RMA_ORDER_SOURCE_IS_NOT_EXIST, source);
        }
        //构建商品基本信息
        vo.setOrderMerchandiseVoList(buildBaseMerchandiseAndItem(json));
        return vo;
    }

    /**
     * 构建ebay同步下退货单参数
     * 
     * @param json
     * @return
     */
    public static void buildRMAOrderByEbay(JSONObject json, RMAOrderVo vo) {
        buildBaseEbayInfo(json, vo);
        if (json.containsKey("ebayReturnId")) {
            vo.setEbayReturnId(json.getString("ebayReturnId"));
        }
        if (json.containsKey("returnDate")) {
            vo.setReturnDate(json.getDate("returnDate"));
        }
        if (json.containsKey("returnQuantity")) {
            vo.setReturnQuantity(json.getInteger("returnQuantity"));
        }
        if (json.containsKey("reason")) {
            vo.setReason(json.getString("reason"));
        }
        if (json.containsKey("refundDue")) {
            vo.setRefundDue(json.getBigDecimal("refundDue"));
        }
        List<RMAOrderMerchandiseVo> orderMerchandiseVoList = new ArrayList<RMAOrderMerchandiseVo>();
        RMAOrderMerchandiseVo mVo = new RMAOrderMerchandiseVo();
        //构建商品基本信息
        buildBaseMerchandise(json, mVo);
        orderMerchandiseVoList.add(mVo);
        vo.setOrderMerchandiseVoList(orderMerchandiseVoList);
    }

    /**
     * 构建ebay基本信息
     * 
     * @param json
     * @param vo
     */
    public static void buildBaseEbayInfo(JSONObject json, RMAOrderVo vo) {
        if (json.containsKey("returnGoodsOrderNo")) {
            vo.setRmaOrderNo(json.getString("returnGoodsOrderNo"));
        }
        if (json.containsKey("ebaySellerId")) {
            vo.setSellerId(json.getString("ebaySellerId"));
        }
        if (json.containsKey("ebayBuyerId")) {
            vo.setBuyerId(json.getString("ebayBuyerId"));
        }
        if (json.containsKey("ebaySite")) {
            vo.setEbaySite(json.getString("ebaySite"));
        }
        if (json.containsKey("itemTitle")) {
            vo.setItemTitle(json.getString("itemTitle"));
        }
    }

    /**
     * 单步下单第二步构建参数
     * @param json
     * @return
     */
    public static RMAOrderVo buildMerchandise(JSONObject json) {
        RMAOrderVo returnOrderVo=new RMAOrderVo();
        if (json.containsKey("returnGoodsOrderNo")) {
            returnOrderVo.setRmaOrderNo(json.getString("returnGoodsOrderNo"));
        }
        //构建商品基本信息
        returnOrderVo.setOrderMerchandiseVoList(buildBaseMerchandiseAndItem(json));
        return returnOrderVo;

    }

    /**
     * 构建商品信息
     * 
     * @param json
     * @return
     */
    public static void buildBaseMerchandise(JSONObject json, RMAOrderMerchandiseVo mVo) {
        if (json.containsKey("itemQuantity")) {
            mVo.setItemQuantity(json.getInteger("itemQuantity"));
        }
        if (json.containsKey("merchandiseSerno")) {
            mVo.setMerchandiseSerno(json.getString("merchandiseSerno"));
        }
        if (json.containsKey("originalMerchandiseSerno")) {
            mVo.setOriginalMerchandiseSerno(json.getString("originalMerchandiseSerno"));
        }
        if (json.containsKey("remarks")) {
            mVo.setRemarks(json.getString("remarks"));
        }
        if (json.containsKey("merchandiseCode")) {
            mVo.setMerchandiseCode(json.getString("merchandiseCode"));
        }
        if (json.containsKey("nameCn")) {
            mVo.setNameCn(json.getString("nameCn"));
        }
        if (json.containsKey("nameEn")) {
            mVo.setNameEn(json.getString("nameEn"));
        }
        //start xuan.wang 需求#9009
        /*if (json.containsKey("length")) {
            mVo.setConfirmLength(json.getBigDecimal("length"));
        }
        if (json.containsKey("width")) {
            mVo.setConfirmWidth(json.getBigDecimal("width"));
        }
        if (json.containsKey("height")) {
            mVo.setConfirmHeight(json.getBigDecimal("height"));
        }
        if (json.containsKey("weight")) {
            mVo.setConfirmWeight(json.getBigDecimal("weight"));
        }
        if (json.containsKey("volume")) {
            mVo.setConfirmVolume(json.getBigDecimal("volume"));
        }*/
        //end xuan.wang 
        if (json.containsKey("declareValue")) {//erp商品数据申报价值小数位可能超出9位,截取后保存
            mVo.setDeclareValue(json.getBigDecimal("declareValue").setScale(9, RoundingMode.HALF_UP));
        }
        if (json.containsKey("formerProductId")) {
            String formerProductId = json.getString("formerProductId");
            if (!StringUtils.isBlank(formerProductId)) {
                mVo.setIsFromSkuMerchandise("Y");
                mVo.setFormerProductId(Long.valueOf(formerProductId));
            } else {
                mVo.setIsFromSkuMerchandise("N");
            }
        }
        if (json.containsKey("formerBarcode")) {
            mVo.setFormerBarcode(json.getString("formerBarcode"));
        }
        if (json.containsKey("declareName")) {
            mVo.setDeclareName(json.getString("declareName"));
        }
        if (json.containsKey("description")) {
            mVo.setDescription(json.getString("description"));
        }
        if (json.containsKey("warehouseCode")) {
            mVo.setWarehouseCode(json.getString("warehouseCode"));
        }
    }
    
    /**
     * 构建商品以及商品信息
     * 
     * @param json
     * @return
     */
    public static List<RMAOrderMerchandiseVo> buildBaseMerchandiseAndItem(JSONObject json) {
    	List<RMAOrderMerchandiseVo> merchandiseList = new ArrayList<RMAOrderMerchandiseVo>();
    	
    	JSONArray array = json.getJSONArray("merchandiseInfoList");
    	for (Object item : array) {
    		RMAOrderMerchandiseVo mVo = new RMAOrderMerchandiseVo();
    		List<RMAItemVo> itemVoList = new ArrayList<RMAItemVo>();
    		JSONObject obj = (JSONObject) item;
    		
            if (obj.containsKey("merchandiseSerno")) {
                mVo.setMerchandiseSerno(obj.getString("merchandiseSerno"));
            }
            if (obj.containsKey("merchandiseCode")) {
                mVo.setMerchandiseCode(obj.getString("merchandiseCode"));
            }
            if (obj.containsKey("nameCn")) {
                mVo.setNameCn(obj.getString("nameCn"));
            }
            if (obj.containsKey("nameEn")) {
                mVo.setNameEn(obj.getString("nameEn"));
            }
            mVo.setSellerLength(obj.getBigDecimal("length"));
            mVo.setSellerWidth(obj.getBigDecimal("width"));
            mVo.setSellerHeight(obj.getBigDecimal("height"));
            mVo.setSellerWeight(obj.getBigDecimal("weight"));
            mVo.setOutboundOrderNo(obj.getString("outboundOrderNo"));
        	RMAItemVo rmaItemVo = new RMAItemVo();
        	rmaItemVo.setItemSerno(obj.getString("itemSerno"));
        	rmaItemVo.setMerchandiseSerno(obj.getString("merchandiseSerno"));
        	String handleMethod = obj.getString("handleMethod"); 
            mVo.setItemQuantity(obj.getInteger("itemQuantity"));
        	rmaItemVo.setHandleMethod(handleMethod);
        	itemVoList.add(rmaItemVo);
            mVo.setItemList(itemVoList);
            merchandiseList.add(mVo);
    	}
    	return merchandiseList;
    }

    /**
     * 构建列表查询参数
     * @param requestData
     * @return
     */
    public static RMAOrderCommand buildSearchOrderCommand(JSONObject requestData) {
        RMAOrderCommand command=new RMAOrderCommand();
        RMAOrderVo vo = new RMAOrderVo();
        // 下拉列表
        if (requestData.containsKey("ebaySellerId")) {
            vo.setSellerId(requestData.getString("ebaySellerId"));
        } else if (requestData.containsKey("ebayBuyerId")) {
            vo.setBuyerId(requestData.getString("ebayBuyerId"));
        } else if (requestData.containsKey("returnGoodsOrderNo")) {
            vo.setRmaOrderNo(requestData.getString("returnGoodsOrderNo"));
        }else if (requestData.containsKey("merchandiseCode")) {
            vo.setMerchandiseCode(requestData.getString("merchandiseCode"));
        }else if (requestData.containsKey("itemTitle")) {
            vo.setItemTitle(requestData.getString("itemTitle"));
        } 
        if(requestData.containsKey("expressNo")){
        	vo.setExpressNo(requestData.getString("expressNo"));
        }
        if (requestData.containsKey("buyerName")) {
        	vo.setBuyerName(requestData.getString("buyerName"));
        }
        if(requestData.containsKey("rmaNo")){
        	vo.setRmaNo(requestData.getString("rmaNo"));
        }
        if(requestData.containsKey("outboundOrderNo")){
        	vo.setOutboundOrderNo(requestData.getString("outboundOrderNo"));
        }
        // 来源
        if (requestData.containsKey("source")) {
            vo.setSource(requestData.getString("source"));
        }
        // 仓库编码
        if (requestData.containsKey("warehouseCode")) {
            vo.setWarehouseCode(requestData.getString("warehouseCode"));
        }
        // 退货单状态
        if (requestData.containsKey("status")) {
            vo.setStatus(requestData.getString("status"));
        }
        //退货单状态
        if (requestData.containsKey("status")) {
            vo.setStatus(requestData.getString("status"));
        }
        //商品是否补齐标记
        if (requestData.containsKey("isComplete")) {
            vo.setIsComplete(requestData.getString("isComplete"));
        }
        // 客户订单号
        if (requestData.containsKey("customerOrderNo")) {
            vo.setCustomerOrderNo(requestData.getString("customerOrderNo"));
        }
        // 销毁出库单号
        if (requestData.containsKey("destroyOutboundOrder")) {
            vo.setDestroyOutboundOrder(requestData.getString("destroyOutboundOrder"));
        }
        // 转为时间类型.
        if (requestData.containsKey("orderDateFrom")) {// 开始时间
            String orderDateStart = requestData.getString("orderDateFrom");
            orderDateStart += " 00:00:00";
            Date from = DateUtil.parse2Date(orderDateStart, DateUtil.FULL_DATE_STRING);
            vo.setOrderStartDate(from);
        }
        if (requestData.containsKey("orderDateFromTo")) {// 结束时间
            String orderDateEnd = requestData.getString("orderDateFromTo");
            orderDateEnd += " 23:59:59";
            Date end = DateUtil.parse2Date(orderDateEnd, DateUtil.FULL_DATE_STRING);
            vo.setOrderEndDate(end);
        }
        command.setReturnOrderVo(vo);
        return command;
    }
    
    /**
     * 构建退货单列表
     * @param rlist
     * @return
     */
    public static List<Map<String, Object>> buildOrderList(List<RMAOrderVo> rlist){
        List<Map<String, Object>> rslist = new ArrayList<Map<String, Object>>();
        for(RMAOrderVo vo:rlist)
        {
            Map<String, Object> map = new HashMap<String, Object>();
            buildBaseInfo(vo,map);
            map.put("returnGoodsOrderNo", vo.getRmaOrderNo());
            rslist.add(map);
        }
        return rslist;
    }
    
    private static void buildBaseInfo(RMAOrderVo vo,Map<String, Object> map){
        List<RMAOrderMerchandiseVo> merchandiselist=vo.getOrderMerchandiseVoList();
        map.put("isPhotograph", vo.getIsPhotograph());
        map.put("expressNo", vo.getExpressNo());
        map.put("customerExpressNo", vo.getCustomerExpressNo());
        map.put("warehouseName", vo.getWarehouseName());
        map.put("warehouseCode", vo.getWarehouseCode());
        map.put("outboundOrderNo", vo.getOutboundOrderNo());
        map.put("createDate", vo.getCreated());
        map.put("status", vo.getStatus());
        map.put("source", vo.getSource());
        map.put("ebayReturnId", vo.getEbayReturnId());
        map.put("ebaySite", vo.getEbaySite());
        map.put("buyerId", vo.getBuyerId());
        map.put("sellerId", vo.getSellerId());
        map.put("itemTitle", vo.getItemTitle());
        map.put("orderDesc", vo.getOrderDesc());
        map.put("warehouseDesc", vo.getWarehouseDesc());
        map.put("rmaNo", vo.getRmaNo());
        map.put("reason", vo.getReason());
        map.put("merchandiselist", merchandiselist);
        map.put("buyerName", vo.getBuyerName());
        map.put("estimateItmeQty", vo.getEstimateItemQty()); //实际单品数量
        map.put("actualItmeQty", vo.getActualItemQty()); //预估单品数量
        map.put("isStartDestroy", vo.getIsStartDestroy());
        map.put("customerOrderNo", vo.getCustomerOrderNo()); // 客户订单号
        map.put("destroyOutboundOrder", vo.getDestroyOutboundOrder()); // 销毁出库单号
        List<Map<String, Object>> mlist = new ArrayList<Map<String, Object>>();
        List<String> imageList=vo.getImageList();
        if(imageList!=null&&imageList.size()>0)
        {
            for(String maddr:imageList)
            {
                Map<String, Object> imageMap = new HashMap<String, Object>();
                imageMap.put("imageAddr", maddr);
                mlist.add(imageMap);
            }
        }
        map.put("imageList", mlist);
    }
    
  /**
   * 查询订单详情
   * @param vo
   * @return
   */
    public static Map<String, Object> buildOrderDetails(RMAOrderVo vo){
        Map<String, Object> data = new HashMap<String, Object>();
        buildBaseInfo(vo,data);
        data.put("returnGoodsOrderNo", vo.getRmaOrderNo());
        data.put("returnGoodsAddress", vo.getRmaAddress());
        data.put("rmaNo", vo.getRmaNo());
        data.put("outboundOrderNo", vo.getOutboundOrderNo());
        List<RMAOrderMerchandiseVo> merchandiselist = vo.getOrderMerchandiseVoList();
        List<Map<String, Object>> rslist = new ArrayList<Map<String, Object>>();
        if(null != merchandiselist && merchandiselist.size() > 0){
        	for (RMAOrderMerchandiseVo rmaOrderMerchandiseVo : merchandiselist) {
            	List<RMAItemVo> item = rmaOrderMerchandiseVo.getItemList();
            	if(item == null) continue;
            	for (RMAItemVo rmaItemVo : item) {
            		Map<String, Object> map = new HashMap<String,Object>();
            		map.put("flist", rmaOrderMerchandiseVo.getFlist());
            		map.put("isComplete", rmaOrderMerchandiseVo.getIsComplete());
            		map.put("confirmLength", rmaOrderMerchandiseVo.getConfirmLength());
            		map.put("confirmWidth", rmaOrderMerchandiseVo.getConfirmWidth());
            		map.put("confirmHeight", rmaOrderMerchandiseVo.getConfirmHeight());
            		map.put("confirmVolume", rmaOrderMerchandiseVo.getConfirmVolume());
            		map.put("confirmWeight", rmaOrderMerchandiseVo.getConfirmWeight());
            		map.put("confirmQty", 1);
                    String merCode = rmaOrderMerchandiseVo.getMerchandiseCode();
                    if (StringUtils.isNotEmpty(merCode)) {
                        if (merCode.contains("(return)") && merCode.indexOf("(return)") > 1) {
                            map.put("merchandiseCode", merCode.substring(0, merCode.indexOf("(return)")) + "(return)");
                        } else {
                            map.put("merchandiseCode", merCode);
                        }
                    }
            		map.put("merchandiseSerno", rmaOrderMerchandiseVo.getMerchandiseSerno());
            		map.put("declareValue", rmaOrderMerchandiseVo.getDeclareValue());
            		map.put("specification", rmaOrderMerchandiseVo.getSpecification());
            		map.put("nameEn", rmaOrderMerchandiseVo.getNameEn());
            		map.put("nameCn", rmaOrderMerchandiseVo.getNameCn());
            		map.put("brand", rmaOrderMerchandiseVo.getBrand());
            		map.put("itemSerno", rmaItemVo.getItemSerno());
            		map.put("handleMethod", rmaItemVo.getHandleMethod());
            		map.put("itemSource", rmaItemVo.getItemSource());
            		map.put("returnOrderNo", rmaOrderMerchandiseVo.getReturnOrderNo());
            		rslist.add(map);
    			}
    		}
        }
        data.put("merchandiselist", rslist);
        data.put("returnQuantity", vo.getReturnQuantity());
        data.put("returnDate", vo.getReturnDate());
        data.put("reason", vo.getReason());
        data.put("refundDue", vo.getRefundDue());
        data.put("orderDesc", vo.getOrderDesc());
        data.put("warehouseDesc", vo.getWarehouseDesc());
        data.put("mdList", vo.getMdImageList());
        data.put("customerExpressNo", vo.getCustomerExpressNo());
        data.put("isStartDestroy", vo.getIsStartDestroy());
        data.put("customerOrderNo", vo.getCustomerOrderNo());
        data.put("destroyOutboundOrder", vo.getDestroyOutboundOrder());
        data.put("orderDesc", vo.getOrderDesc());
        data.put("warehouseDesc", vo.getWarehouseDesc());
        data.put("createDate", vo.getCreated());
        data.put("updateExpressNoDate", vo.getUpdateExpressNoDate());
        data.put("handleStatus", vo.getHandleStatus());
        return data;
    }
    
    /**
     * 查询订单详情
     * @param vo
     * @return
     */
	public static Map<String, Object> buildOrderDetailsAnItemSerno(RMAOrderVo vo) {
		Map<String, Object> data = new HashMap<String, Object>();
		data.put("returnGoodsOrderNo", vo.getRmaOrderNo());
		data.put("expressNo", vo.getExpressNo());
		List<Map<String, Object>> itemMapList=new ArrayList<Map<String,Object>>();
		List<RMAOrderMerchandiseVo> merchandiselist = vo.getOrderMerchandiseVoList();
		for (RMAOrderMerchandiseVo rmaOrderMerchandiseVo : merchandiselist) {
			List<RMAItemVo> itemList = rmaOrderMerchandiseVo.getItemList();
			for (RMAItemVo rmaItemVo : itemList) {
				Map<String, Object> imageMap = new HashMap<String, Object>();
				imageMap.put("itemSerno", rmaItemVo.getItemSerno());
				imageMap.put("handleMethod", rmaItemVo.getHandleMethod());
				itemMapList.add(imageMap);
			}
		}
		data.put("itemList", itemMapList);
		data.put("warehouseCode", vo.getWarehouseCode());
		return data;
	}
   
    public static List<Map<String, Object>> buildTodaoList(List<RMAClaimTagVo> voList){
        List<Map<String, Object>> mapList=new ArrayList<Map<String,Object>>();
        for(RMAClaimTagVo vo:voList)
        {
            Map<String, Object> map=new HashMap<String, Object>();
            map.put("expressNo", vo.getReturnExpressNo());
            map.put("claimTagNo", vo.getClaimTagNo());
            map.put("date", vo.getDate());
            map.put("endDate", vo.getEndDate());
            map.put("warehouseCode", vo.getWarehouseCode());
            List<Map<String, Object>> imageList=new ArrayList<Map<String,Object>>();
            List<RMAFilePathVo> imagePathList=vo.getrMAFilePathVoList();
            if(imagePathList!=null&&imagePathList.size()>0)
            {
                for(RMAFilePathVo rMAFilePathVo:imagePathList)
                {
                    Map<String, Object> imageMap=new HashMap<String, Object>();
                    imageMap.put("imageAddr", rMAFilePathVo.getUrl());
                    imageList.add(imageMap);
                }
            }
            map.put("imageList",imageList);
            mapList.add(map);
        }
        return mapList;
    }
    
    public static Map<String, Object> buildMerchandise(List<RMAOrderMerchandiseVo> merchandiselist){
    	Map<String, Object> data = new HashMap<String, Object>();
        List<Map<String, Object>> rslist = new ArrayList<Map<String, Object>>();
        for (RMAOrderMerchandiseVo rmaOrderMerchandiseVo : merchandiselist) {
    		Map<String, Object> map = new HashMap<String,Object>();
    		map.put("confirmLength", rmaOrderMerchandiseVo.getConfirmLength());
    		map.put("confirmWidth", rmaOrderMerchandiseVo.getConfirmWidth());
    		map.put("confirmHeight", rmaOrderMerchandiseVo.getConfirmHeight());
    		map.put("confirmVolume", rmaOrderMerchandiseVo.getConfirmVolume());
    		map.put("confirmWeight", rmaOrderMerchandiseVo.getConfirmWeight());
    		map.put("usableQty", rmaOrderMerchandiseVo.getConfirmQty());
    		map.put("inStockQty", rmaOrderMerchandiseVo.getConfirmQty());
    		map.put("merchandiseCode", rmaOrderMerchandiseVo.getMerchandiseCode());
    		map.put("merchandiseSerno", rmaOrderMerchandiseVo.getMerchandiseSerno());
    		map.put("declareValue", rmaOrderMerchandiseVo.getDeclareValue());
    		map.put("specification", rmaOrderMerchandiseVo.getSpecification());
    		map.put("merchandiseEnName", rmaOrderMerchandiseVo.getNameEn());
    		map.put("merchandiseName", rmaOrderMerchandiseVo.getNameCn());
    		map.put("brand", rmaOrderMerchandiseVo.getBrand());
    		map.put("returnOrderNo", rmaOrderMerchandiseVo.getReturnOrderNo());
    		rslist.add(map);
		}
        data.put("merchandiselist", rslist);
        return data;
    }
    
    /**
     * 构建导出退货单数据
     */
    public static Map<String, Object> buildExportReturnOrder(List<RMAOrderVo> pList){
        Map<String, Object> data = new HashMap<String, Object>();
        List<Map<String, Object>> rslist = new ArrayList<Map<String, Object>>();
        for(RMAOrderVo vo : pList){
            Map<String, Object> map = null;
            if(vo.getOrderMerchandiseVoList() == null || vo.getOrderMerchandiseVoList().size() < 0){
                map = new HashMap<String, Object>();
                map.put("returnGoodsOrderNo", vo.getRmaOrderNo());// 退货单号
                map.put("source", vo.getSource());// 来源
                map.put("expressNo", vo.getExpressNo());// 退运单号
                map.put("outboundOrderNo", vo.getOutboundOrderNo());// 出库单号
                map.put("warehouseName", vo.getWarehouseName());// 仓库名称
                map.put("warehouseCode", vo.getWarehouseCode());// 仓库编码
                map.put("reason", vo.getReason());// 退货原因
                map.put("createDate", vo.getOrderDate());// 创建时间
                map.put("status", vo.getStatus());// 状态
                map.put("orderDesc", vo.getOrderDesc());// 订单描述
                map.put("rmaNo", vo.getRmaNo());// rma号
                map.put("warehouseDesc", vo.getWarehouseDesc());// 仓库备注
                rslist.add(map);
                continue;
            }
            for (RMAOrderMerchandiseVo me : vo.getOrderMerchandiseVoList()) {
                map = new HashMap<String, Object>();
                map.put("returnGoodsOrderNo", vo.getRmaOrderNo());// 退货单号
                map.put("source", vo.getSource());// 来源
                map.put("expressNo", vo.getExpressNo());// 退运单号
                map.put("outboundOrderNo", vo.getOutboundOrderNo());// 出库单号
                map.put("warehouseName", vo.getWarehouseName());// 仓库名称
                map.put("warehouseCode", vo.getWarehouseCode());// 仓库编码
                map.put("reason", vo.getReason());// 退货原因
                map.put("createDate", vo.getOrderDate());// 创建时间
                map.put("status", vo.getStatus());// 状态
                map.put("orderDesc", vo.getOrderDesc());// 订单描述
                map.put("rmaNo", vo.getRmaNo());// rma号
                map.put("warehouseDesc", vo.getWarehouseDesc());// 仓库备注
                map.put("merchandiseCode", me.getMerchandiseCode());// 商品编码
                map.put("specification", me.getSpecification());// 规格
                map.put("nameCn", me.getNameCn());// 商品名称
                map.put("nameEn", me.getNameEn());// 英文名称
                map.put("length", me.getConfirmLength());// 长
                map.put("width", me.getConfirmWidth());// 宽
                map.put("height", me.getConfirmHeight());// 高
                map.put("weight", me.getConfirmWeight());// 重量
                map.put("volume", me.getConfirmVolume());// 体积
                map.put("declareValue", me.getDeclareValue()); // 申报价值
                map.put("qty", me.getConfirmQty()); // 商品数量
                rslist.add(map);
            }
        }
        data.put("list", rslist);
        return data;
    }
}
